<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('项目图片') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('图片类型')" prop="imgType">
        <el-select v-model="queryParams.imgType" :placeholder="$t('图片类型')" clearable>
          <el-option
            v-for="dict in imgTypeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
        <el-button v-hasPermi="['deal:picture:edit']" type="primary" icon="el-icon-plus" size="mini" @click="addHandle">{{ $t('新增') }}</el-button>
      </el-form-item>
    </el-form>

    <div v-loading="loading">
      <el-row :gutter="20">
        <div v-for="(row) in dealPictureList" :key="row.id">
          <el-col :span="12">
            <div style="width: 100%; text-align: right; z-index: 2002; margin-bottom: -25px; margin-left: -8px; position: relative;cursor: pointer;">
              <i class="el-icon-s-tools" @click="updateHandle(row)" />
              <i class="el-icon-delete-solid" @click="deleteHandle(row)" />
            </div>
            <el-carousel indicator-position="outside" height="250" style="z-index: 2001; box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1); text-align: center;">
              <el-carousel-item v-for="img in row.children" :key="img.id">
                <!-- 轮播图片 -->
                <el-image
                  :style="{ height: '100%' }"
                  :src="javaUrl + '/file/fileBase/common/download?id=' + img.thumbnailId + '&Authorization=' + token"
                  :preview-src-list="[javaUrl + '/file/fileBase/common/download?id=' + img.fileId + '&Authorization=' + token]"
                  :z-index="2003"
                />
              </el-carousel-item>
            </el-carousel>
          </el-col>
        </div>
      </el-row>
      <el-empty v-if="total<=0" :description="$t('暂无内容')" />
    </div>
    <pagination
      v-show="total>0"
      :total="total"
      :page-sizes="[2, 4, 6, 8, 10, 20]"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改地产项目图片对话框 -->
    <el-dialog :title="$t(title)" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <dealPictureForm ref="dealPictureForm" />
    </el-dialog>
  </div>
</template>

<script>
import { listDealPicture, delDealPicture } from '@/api/deal/estate/picture/dealPicture'
import { getToken } from '@/utils/auth'
import { config } from '@/utils'
import dealPictureForm from './dealPictureForm.vue'

export default {
  components: {
    dealPictureForm
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 地产项目图片表格数据
      dealPictureList: [],
      // 弹出层标题
      title: '项目图片',
      // 是否显示弹出层
      formOpen: false,
      // 图片类型字典
      imgTypeOptions: [],
      // 查询参数
      queryParams: {
        parentId: 0,
        dealId: this.$route.query.id,
        imgType: undefined,
        fileId: undefined,
        thumbnailId: undefined,
        other: undefined,
        pageNum: 1,
        pageSize: 6
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      token: getToken(),
      javaUrl: config.baseURL
    }
  },
  created() {
    this.getList()
    this.getDicts('real_estate_picture_type').then(response => {
      this.imgTypeOptions = response.data
    })
  },
  methods: {
    /** 查询地产项目图片列表 */
    getList() {
      this.loading = true
      listDealPicture(this.queryParams).then(response => {
        console.log(response)
        this.dealPictureList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 图片类型字典翻译
    imgTypeFormat(row) {
      return this.selectDictLabel(this.imgTypeOptions, row.imgType)
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        dealId: this.$route.query.id,
        imgType: undefined,
        fileId: undefined,
        thumbnailId: undefined,
        other: undefined,
        remark: undefined,
        createTime: undefined,
        updateTime: undefined,
        createBy: undefined,
        updateBy: undefined,
        delFlag: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
      this.formOpen = true
      this.$nextTick(() => {
        this.$refs.dealPictureForm.init(null)
      })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
      this.formOpen = true
      this.$nextTick(() => {
        // 调用form页面的 init 方法初始化数据
        this.$refs.dealPictureForm.init(row)
      })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
      this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        type: 'warning'
      }).then(function() {
        return delDealPicture(row.id)
      }).then(() => {
        this.getList()
        this.msgSuccess(this.$t('删除成功'))
      }).catch(function() {
      })
    }
  }
}
</script>
  <style lang="scss" scoped>
  .el-carousel__item h3 {
  color: #475669;
  font-size: 18px;
  opacity: 0.75;
  line-height: 220px;
  margin: 0;
  }

  .el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
  }

  .el-carousel__item:nth-child(2n+1) {
  background-color: #d3dce6;
  }
</style>

